package com.corechina.apex_osswords.controller;


import com.corechina.apex_osswords.common.Response;
import com.corechina.apex_osswords.common.SysLog;
import com.corechina.apex_osswords.domain.entity.CoreEquipment;
import com.corechina.apex_osswords.service.ICoreEquipmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 设备表 前端控制器
 * </p>
 *
 * @author cc
 * @since 2022-12-09
 */

@Api(tags = "设备管理")
@RestController
@RequestMapping("/core/equipment")
public class CoreEquipmentController {

    @Autowired
    private ICoreEquipmentService iCoreEquipmentService;

    @ApiOperation("新增")
    @SysLog("新增设备")
    @PostMapping("/add")
    public Response add(@RequestBody CoreEquipment coreEquipment) {
        return iCoreEquipmentService.add(coreEquipment);
    }


    @ApiOperation("编辑")
    @SysLog("编辑设备")
    @PutMapping("/update")
    public Response update(@RequestBody CoreEquipment coreEquipment) {
        return iCoreEquipmentService.update(coreEquipment);
    }

    @ApiModelProperty("删除")
    @SysLog("删除设备")
    @DeleteMapping("/del")
    public Response del(Integer id) {
        if (iCoreEquipmentService.checkEquipment(id)) {
            return Response.error("设备有关联工单，无法删除");
        }
        if (iCoreEquipmentService.removeById(id)) {
            return Response.ok();
        }
        return Response.error();
    }

    @ApiOperation("列表")
    @GetMapping("/getList")
    public Response getList(String name, Integer place, Integer serviceId, Integer type, Integer projectId, Integer pageIndex, Integer pageSize) {
        return iCoreEquipmentService.getList(name, place, serviceId, type, projectId, pageIndex, pageSize);
    }

    @ApiOperation("详情")
    @GetMapping("/getOne")
    public Response getOne(Integer id) {
        return iCoreEquipmentService.getOne(id);
    }


}

